<%@ tag pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<script type="text/javascript">
<%
String ctx =  request.getContextPath();
%>

function getCitys(val){
	$("#city option:gt(0)").remove();
	$("#municipality option:gt(0)").remove();
	$.ajax({
		url:"<%=ctx %>/home/getCityListByProvince",
		type:"POST",
		dataType:"json",
		async:false,  
		data:"provincecode="+val,
		success:function(data){
			if(data){
				$.each(data,function(index,value){
					$("#city").append("<option value='"+value.code+"'>"+value.name+"</option>");
				});
			}
		}
	});
}

function getMunicipality(cval){
	$("#municipality option:gt(0)").remove();
	var pval = $("#province").val();
	$.ajax({
		url:"<%=ctx %>/home/getMunicipalityShowList",
		type:"POST",
		dataType:"json",
		async:false,  
		data:{provincecode:pval,citycode:cval},
		success:function(data){
			if(data){
				$.each(data,function(index,value){
					$("#municipality").append("<option value='"+value.code+"'>"+value.name+"</option>");
				});
			}
		}
	});
}
</script>


<%@ attribute name="type"%>
<%@ attribute name="style"%>
<%@ attribute name="styleClass"%>
<%@ attribute name="provinceList" required="true" type="java.util.List"%>

<%@ attribute name="provinceName"%>
<%@ attribute name="cityName"%>
<%@ attribute name="municipalityName"%>
<%-- <%@ attribute name="ctx" %> --%>

<c:choose>
	<c:when test="${type ==1}">
		<select name="${provinceName}" id="province"
			onchange="getCitys(this.value)" class="${styleClass }"
			style="${style}">
			<option value="">请选择</option>
			<c:forEach items="${provinceList}" var="p">
				<option value="${p.code}">${p.name}</option>
			</c:forEach>
		</select>
	</c:when>
	<c:when test="${type ==2}">
		<select name="${provinceName}" id="province"
			onchange="getCitys(this.value)" class="${styleClass }"
			style="${style}">
			<option value="">请选择</option>
			<c:forEach items="${provinceList}" var="p">
				<option value="${p.code}">${p.name}</option>
			</c:forEach>
		</select>
		<%-- 	    <select name ="${cityName}" id="city" onchange="getMunicipality(this.value)"  class="${styleClass }" style="${style}" > --%>
		<select name="${cityName}" id="city" class="${styleClass }"
			style="${style}">
			<option value="">请选择</option>
		</select>
	</c:when>
	<c:when test="${type ==3}">
		<select name="${provinceName}" id="province" onchange="getCitys(this.value)" class="${styleClass }" style="${style}">
			<option value="">请选择</option>
			<c:forEach items="${provinceList}" var="p">
				<option value="${p.code}">${p.name}</option>
			</c:forEach>
		</select>
		<select name="${cityName}" id="city" class="${styleClass }" style="${style}" onchange="getMunicipality(this.value)">
			<%-- 		<select name ="${cityName}" id="city" onchange="getMunicipality(this.value)"  class="${styleClass }" style="${style}" > --%>
			<option value="">请选择</option>
		</select>
	    <!--  <input type="hidden" name="municipality" id="municipality" value="" /> -->
	     <select name ="${municipalityName}" id="municipality" class="${styleClass }" style="${style}" >
	       <option value="">请选择</option>
	     </select>
	</c:when>
</c:choose>